home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Library / Manuels & Misc / Assembly / AOA.ZIP / CH23 / GRABSCRN.ASM
Encoding:
Assembly Source File  |  1994-07-27  |  4.1 KB  |  192 lines

  1. ; GRABSCRN.ASM
  2. ;
  3. ; A short TSR to capture the current display screen and display it later.
  4. ;
  5. ; Note that this code does not patch into int 2Fh (multiplex interrupt)
  6. ; nor can you remove this code from memory except by rebooting.
  7. ; If you want to be able to do these two things (as well as check for
  8. ; a previous installation), see the chapter on resident programs.  Such
  9. ; code was omitted from this program because of length constraints.
  10. ;
  11. ;
  12. ; cseg and EndResident must occur before the standard library segments!
  13.  
  14. cseg        segment    para public 'code'
  15. OldInt9        dword    ?
  16. ScreenSave    byte    4096 dup (?)
  17. cseg        ends
  18.  
  19. ; Marker segment, to find the end of the resident section.
  20.  
  21. EndResident    segment    para public 'Resident'
  22. EndResident    ends
  23.  
  24.         .xlist
  25.         include     stdlib.a
  26.         includelib    stdlib.lib
  27.         .list
  28.  
  29.  
  30. RShiftScan    equ    36h
  31. LShiftScan    equ    2ah
  32.  
  33. ; Bits for the shift/modifier keys
  34.  
  35. RShfBit        equ    1
  36. LShfBit        equ    2
  37.  
  38. KbdFlags    equ    <byte ptr ds:[17h]>
  39.  
  40. byp        equ    <byte ptr>
  41.  
  42.  
  43. ; Screen segment address.  This value is for color displays only.
  44. ; Change to B000h if you want to use this program on a mono display.
  45.  
  46. ScreenSeg    equ    0B800h
  47.  
  48. cseg        segment    para public 'code'
  49.         assume    ds:nothing
  50.  
  51.  
  52.  
  53. ; MyInt9-    INT 9 ISR.  This routine reads the keyboard port to see
  54. ;        if a shift key scan code just came along.  If the right
  55. ;        shift bit is set in KbdFlags the a left shift key scan
  56. ;        code comes along, we want to copy the data from our
  57. ;        internal buffer to the screen's memory.  If the left shift
  58. ;        bit is set and a right shift key scan code comes along,
  59. ;        we want to copy the screen memory into our local array.
  60. ;        In any case (including none of the above), we always transfer
  61. ;        control to the original INT 9 handler.
  62.  
  63. MyInt9        proc    far
  64.         push    ds
  65.         push    ax
  66.  
  67.         mov    ax, 40h
  68.         mov    ds, ax
  69.  
  70.         in    al, 60h            ;Read the keyboard port.
  71.         cmp    al, RShiftScan        ;Right shift just go down?
  72.         je    DoRight
  73.         cmp    al, LShiftScan        ;How about the left shift?
  74.         jne    QuitMyInt9
  75.  
  76. ; If this is the left scan code, see if the right shift key is already
  77. ; down.
  78.  
  79.         test    KbdFlags, RShfBit
  80.         je    QuitMyInt9        ;Branch if no
  81.  
  82. ; Okay, right shift was down and we just saw left shift, copy our local
  83. ; data back to screen memory:
  84.  
  85.         pushf
  86.         push    es
  87.         push    cx
  88.         push    di
  89.         push    si
  90.         mov    cx, 2048
  91.         mov    si, cs
  92.         mov    ds, si
  93.         lea    si, ScreenSave
  94.         mov    di, ScreenSeg
  95.         mov    es, di
  96.         xor    di, di
  97.         jmp    DoMove
  98.  
  99. ; Okay, we just saw the right shift key scan code, see if the left shift
  100. ; key is already down.  If so, save the current screen data to our local
  101. ; array.
  102.  
  103. DoRight:    test    KbdFlags, LShfBit
  104.         je    QuitMyInt9
  105.  
  106.         pushf
  107.         push    es
  108.         push    cx
  109.         push    di
  110.         push    si
  111.         mov    cx, 2048
  112.         mov    ax, cs
  113.         mov    es, ax
  114.         lea    di, ScreenSave
  115.         mov    si, ScreenSeg
  116.         mov    ds, si
  117.         xor    si, si
  118.  
  119. DoMove:     cld
  120.     rep    movsw
  121.         pop    si
  122.         pop    di
  123.         pop    cx
  124.         pop    es
  125.         popf
  126. QuitMyInt9:
  127.         pop    ax
  128.         pop    ds
  129.         jmp    OldInt9
  130. MyInt9        endp
  131.  
  132.  
  133.  
  134. Main        proc
  135.         assume    ds:cseg
  136.  
  137.         mov    ax, cseg
  138.         mov    ds, ax
  139.  
  140.         print
  141.         byte    "Screen capture TSR",cr,lf
  142.         byte    "Pressing left shift, then right shift, captures "
  143.         byte    "the current screen.",cr,lf
  144.         byte    "Pressing right shift, then left shift, displays "
  145.         byte    "the last captured screen.",cr,lf
  146.         byte    0
  147.  
  148. ; Patch into the INT 9 interrupt vector.  Note that the
  149. ; statements above have made cseg the current data segment,
  150. ; so we can store the old INT 9 value directly into
  151. ; the OldInt9 variable.
  152.  
  153.         cli                ;Turn off interrupts!
  154.         mov    ax, 0
  155.         mov    es, ax
  156.         mov    ax, es:[9*4]
  157.         mov    word ptr OldInt9, ax
  158.         mov     ax, es:[9*4 + 2]
  159.         mov    word ptr OldInt9+2, ax
  160.         mov    es:[9*4], offset MyInt9
  161.         mov    es:[9*4+2], cs
  162.         sti                ;Okay, ints back on.
  163.  
  164.  
  165. ; We're hooked up, the only thing that remains is to terminate and
  166. ; stay resident.
  167.  
  168.         print
  169.         byte    "Installed.",cr,lf,0
  170.  
  171.         mov    ah, 62h            ;Get this program's PSP
  172.         int    21h            ; value.
  173.  
  174.         mov    dx, EndResident        ;Compute size of program.
  175.         sub    dx, bx
  176.         mov    ax, 3100h        ;DOS TSR command.
  177.         int    21h
  178. Main        endp
  179. cseg        ends
  180.  
  181. sseg        segment    para stack 'stack'
  182. stk        db    1024 dup ("stack   ")
  183. sseg        ends
  184.  
  185. zzzzzzseg    segment    para public 'zzzzzz'
  186. LastBytes    db    16 dup (?)
  187. zzzzzzseg    ends
  188.         end    Main
  189.  
  190.  
  191.  
  192.